from scrapy import signals


class MyExtend(object):
    def __init__(self, value):
        pass

    @classmethod
    def from_crawler(cls, crawler):
        val = crawler.settings.getint('MMM')
        ext = cls(val)
        # 在scrapy中注册信号 spider_opened， spider_open为触发的函数
        crawler.signals.connect(ext.spider_open, signal=signals.spider_opened)
        # 在scrapy中注册信号 spider_closed， spider_close为触发的函数
        crawler.signals.connect(ext.spider_close, signal=signals.spider_closed)

        return ext

    def spider_open(self):
        print('open')

    def spider_close(self):
        print('close')
